using System;
using System.Windows.Forms;
using OutlookBarWorkspaceQuickstart.Common;
using Microsoft.Practices.CompositeUI;
using Microsoft.Practices.CompositeUI.Commands;
using OutlookBarWorkspaceQuickstart.CalendarModule.Constants;
using Microsoft.Practices.CompositeUI.EventBroker;
using OutlookBarWorkspaceQuickstart.Common.Services;
using System.Drawing;

namespace OutlookBarWorkspaceQuickstart.CalendarModule
{
    public class ModuleController : WorkItemController
    {
        private ToolStripService _uiService;

        public override void Run()
        {
            AddServices();            
            AddViews();
        }

        private void AddServices()
        {
            _uiService = WorkItem.Services.AddNew<ToolStripService>();           
        }
        
        private void AddViews()
        {
            Months context = WorkItem.Items.AddNew<Months>("Months");            
            WorkItem.Workspaces[WorkspaceNames.OutlookBar].Show(context);

            WorkItem.Items.AddNew<Calendar>("Calendar");
        }

        [EventSubscription(EventTopicNames.ShowCalendar)]
        public void ShowCalendar(object sender, EventArgs e)
        {
            _uiService.RegisterToolStrip(new Toolbar().ModuleToolStrip, UIExtensionSiteNames.MainToolbar);
            
            WorkItem.Workspaces[WorkspaceNames.PrimaryWorkspace].Show(WorkItem.Items.Get("Calendar"));
            WorkItem.Workspaces[WorkspaceNames.RightWorkspace].Show(new UserControl());
        }

        [CommandHandler("New")]
        public void New(object sender, EventArgs e)
        {
            MessageBox.Show("Pressed New default button...");
        }
        
        [CommandHandler("NewAppointment")]
        public void NewAppointment(object sender, EventArgs e)
        {
            MessageBox.Show("Pressed New Appointment button...");
        }
    }
}
